define(['game/constants/CampConstants'], function (CampConstants) {

	var ImprovementConstants = {

		improvements: {
			beacon: {
				description: "在大面积上发光，使扫掠变得不那么危险.",
			},
			camp: {
				canBeDismantled: false,
			},
			home: {
				displayNames: ["家园"],
				description: "营地的基础。",
				useActionName: "休息",
				improvementLevelsPerTechLevel: 0,
				sortScore: 10000,
			},
			campfire: {
				displayNames: ["营火", "城火", "恒火"],
				description: "增加谣言生成并解锁升级。",
				useActionName: "坐下",
				improvementLevelsPerTechLevel: 5,
				improvementLevelsPerMajorLevel: 5,
				logMsgImproved: "Made the campfire a bit cozier",
			},
			house: {
				displayNames: ["小屋", "房屋"],
				description: "一个供" + CampConstants.POPULATION_PER_HOUSE + " 个人休息的地方.",
				improvementLevelsPerTechLevel: 0,
				sortScore: 9000,
			},
			house2: {
				description: ["房子 " + CampConstants.POPULATION_PER_HOUSE2 + " 个人.", "房子 " + CampConstants.POPULATION_PER_HOUSE2_LEVEL_2 + " 个人."],
				sortScore: 9000,
				improvementLevelsPerTechLevel: 1,
				improvementLevelsPerMajorLevel: 1,
			},
			storage: {
				displayNames: ["仓库"],
				description: "增加资源存储.",
				improvementLevelsPerTechLevel: 1,
				sortScore: 8000,
			},
			hospital: {
				canBeDismantled: true,
				displayNames: ["诊所", "医院", "医疗中心"],
				description: "愈合伤口.",
				useActionName: "治疗",
				useActionName2: "增强",
				improvementLevelsPerTechLevel: 1,
				improvementLevelsPerMajorLevel: 1,
			},
			market: {
				displayNames: ['市场'],
				canBeDismantled: true,
				description: "允许外国贸易商参观.",
				useActionName: "访问",
				improvementLevelsPerTechLevel: 5,
				improvementLevelsPerMajorLevel: 5,
			},
			inn: {
				displayNames: ["旅店"],
				canBeDismantled: true,
				description: "增加谣言，招募追随者.",
				improvementLevelsPerTechLevel: 5,
				improvementLevelsPerMajorLevel: 5,
			},
			library: {
				displayNames: ["图书馆"],
				canBeDismantled: true,
				description: "生成传闻.",
				useActionName: "学习",
				improvementLevelsPerTechLevel: 5,
				logMsgImproved: "Upgraded the library",
			},
			darkfarm: {
				displayNames: ["蜗牛养殖场"],
				canBeDismantled: true,
				description: "生产食物.",
				improvementLevelsPerTechLevel: 5,
				sortScore: 10,
			},
			aqueduct: {
				displayNames: ["水渠"],
				description: "生产水.",
				improvementLevelsPerTechLevel: 1,
			},
			temple: {
				displayNames: ["寺庙"],
				canBeDismantled: true,
				description: "宗教和文化活动的中心地点.",
				useActionName: "捐赠",
				improvementLevelsPerTechLevel: 5,
			},
			shrine: {
				displayNames: ["神庙"],
				canBeDismantled: true,
				description: "一个与奇怪的灵魂联系的地方.",
				useActionName: "打坐",
				improvementLevelsPerTechLevel: 5,
				improvementLevelsPerMajorLevel: 5,
			},
			barracks: {
				displayNames: ["兵营"],
				canBeDismantled: true,
				description: "为改善营地防御的士兵提供住房.",
				improvementLevelsPerTechLevel: 1,
			},
			apothecary: {
				displayNames: ["化学师"],
				canBeDismantled: true,
				description: "使药品生产成为可能.",
				improvementLevelsPerTechLevel: 5,
				sortScore: 50,
			},
			smithy: {
				displayNames: ["铁匠铺"],
				canBeDismantled: true,
				description: "工具人员工作区.",
				improvementLevelsPerTechLevel: 5,
				sortScore: 50,
			},
			cementmill: {
				displayNames: ["水泥厂"],
				canBeDismantled: true,
				description: "能够生产一种新型建筑材料.",
				improvementLevelsPerTechLevel: 5,
				sortScore: 50,
			},
			stable: {
				displayNames: ["贸易队伍"],
				canBeDismantled: true,
				description: "设立贸易车队的空间.",
				improvementLevelsPerTechLevel: 1,
			},
			fortification: {
				displayNames: ["要塞"],
				canBeDismantled: true,
				description: "增强营地防御.",
				improvementLevelsPerTechLevel: 5,
				improvementLevelsPerMajorLevel: 5,
			},
			researchcenter: {
				displayNames: ["研究中心"],
				canBeDismantled: true,
				description: "生成传闻.",
				improvementLevelsPerTechLevel: 5,
			},
			tradepost: {
				displayNames: ["贸易站"],
				description: "将营地连接到贸易网络.",
				improvementLevelsPerTechLevel: 1,
				improvementLevelsPerMajorLevel: 1,
			},
			radiotower: {
				displayNames: ["天线塔"],
				canBeDismantled: true,
				description: "提高声誉.",
				improvementLevelsPerTechLevel: 5,
			},
			robotFactory: {
				displayNames: ["机器人工厂"],
				canBeDismantled: true,
				description: "实现工人机器人的生产和存储.",
				improvementLevelsPerTechLevel: 1,
				logMsgImproved: "Modernized the robot factory"
			},
			lights: {
				displayNames: ["灯塔"],
				canBeDismantled: true,
				description: "永远远离黑暗.",
			},
			square: {
				displayNames: ["广场"],
				canBeDismantled: true,
				description: "一个放松和社交的地方.",
				improvementLevelsPerTechLevel: 1,
			},
			garden: {
				displayNames: ["花园"],
				canBeDismantled: true,
				description: "混凝土沙漠中的一抹美丽.",
				improvementLevelsPerTechLevel: 1,
			},
			generator: {
				displayNames: ["发电机"],
				canBeDismantled: true,
				description: "每栋房屋增加 (" + CampConstants.REPUTATION_PER_HOUSE_FROM_GENERATOR + "% 声誉奖励).",
				improvementLevelsPerTechLevel: 10,
				logMsgImproved: "Fixed up the generator",
			},
			collector_water: {
				improvementLevelsPerTechLevel: 1,
			},
			collector_food: {
				improvementLevelsPerTechLevel: 1,
			},
			greenhouse: {
				isProject: true,
			},
			luxuryOutpost: {
				isProject: true,
			},
			passageUpStairs: {
				isPassage: true,
				isProject: true,
			},
			passageUpElevator: {
				isPassage: true,
				isProject: true,
			},
			passageUpHole: {
				isPassage: true,
				isProject: true,
			},
			passageDownStairs: {
				isPassage: true,
				isProject: true,
			},
			passageDownElevator: {
				isPassage: true,
				isProject: true,
			},
			passageDownHole: {
				isPassage: true,
				isProject: true,
			},
			tradepost_connector: {
				isProject: true,
			},
			spaceship1: {
				isProject: true,
			},
			spaceship2: {
				isProject: true,
			},
			spaceship3: {
				isProject: true,
			},
			sundome: {
				isProject: true,
			},
		},

		getDef: function (improvementID) {
			let def = this.improvements[improvementID];
			if (!def) {
				let id = this.getImprovementID(improvementID);
				def = this.improvements[id];
			}
			if (!def) {
				log.w("未发现任何改进: " + improvementID);
				return {};
			}
			return def;
		},

		getMaxLevel: function (improvementID, techLevel) {
			techLevel = techLevel || 1;
			let def = this.getDef(improvementID);
			if (!def) return 1;

			let improvementLevelsPerTechLevel = def.improvementLevelsPerTechLevel || 0;

			return Math.max(1, improvementLevelsPerTechLevel * techLevel);
		},

		getRequiredTechLevelForLevel: function (improvementID, level) {
			let def = this.getDef(improvementID);
			if (!def) return 1;

			let improvementLevelsPerTechLevel = def.improvementLevelsPerTechLevel || 0;
			if (improvementLevelsPerTechLevel < 1) {
				return 1;
			}

			return Math.ceil(level / improvementLevelsPerTechLevel);
		},

		getMajorLevel: function (improvementID, level) {
			let def = this.getDef(improvementID);
			if (!def) return 1;

			let improvementLevelsPerMajorLevel = def.improvementLevelsPerMajorLevel || 0;
			if (improvementLevelsPerMajorLevel < 1) {
				return 1;
			}

			return Math.ceil(level / improvementLevelsPerMajorLevel);
		},

		getImprovementID: function (improvementName) {
			for (var key in improvementNames) {
				var name = improvementNames[key];
				if (name == improvementName) return key;
			}
			return null;
		},

		getImprovementDisplayName: function (improvementID, level) {
			level = level || 1;
			let def = this.getDef(improvementID);
			let result = improvementNames[improvementID] || "[" + improvementID + "]";
			if (!def) return result;
			let names = def.displayNames;
			if (!names || names.length == 0) return result;
			let majorLevel = this.getMajorLevel(improvementID, level);
			let index = Math.min(majorLevel - 1, names.length - 1);
			return names[index];
		},

		getImproveActionName: function (improvementName) {
			let improvementID = ImprovementConstants.getImprovementID(improvementName);
			let improvementType = getImprovementType(improvementName);
			if (improvementType == improvementTypes.camp) {
				return "improve_in_" + improvementID;
			} else {
				return "improve_out_" + improvementID;
			}
		},

		getImprovementDescription: function (improvementID, level) {
			level = level || 1;
			let def = this.getDef(improvementID);
			if (!def) return "";
			let descriptions = def.description;
			if (!descriptions || descriptions.length == 0) return "";
			if (typeof descriptions === "string") return descriptions;
			let majorLevel = this.getMajorLevel(improvementID, level);
			let index = Math.min(majorLevel - 1, descriptions.length - 1);
			return descriptions[index];
		},

		isProject: function (improvementName) {
			let improvementID = ImprovementConstants.getImprovementID(improvementName);
			let improvementDef = ImprovementConstants.getDef(improvementID);
			return improvementDef && improvementDef.isProject;
		},

		getImprovementActionOrdinalForImprovementLevel: function (improvementLevel) {
			return improvementLevel - 1;
		},

		getImprovedLogMessage: function (improvementID, level) {
			let def = this.getDef(improvementID);
			return def && def.logMsgImproved ? def.logMsgImproved : "改进了 " + this.getImprovementDisplayName(improvementID, level);
		}

	};
	return ImprovementConstants;
});
